UnloadSeg
UnloadSeg
Unlock a code segment and make it purgeable Ptr rtnAddr ; address of any routine in a segment to unload UnloadSeg unlocks a code resource (type 'CODE') and makes it purgeable (unless it is called from code in that same segment). When a memory shortage
occurs, the specified segment will be purged from memory. Any subsequent
call to any routines in the unloaded segment will cause it to be swapped back
into memory.
rtnAddr is the address of any function in the application. The code segment in
which the function resides will be unlocked and made purgeable.
Notes: UnloadSeg ignores calls that would unlock the segment from which the call was made. Also, the main segment of an application (first segment
executed, the 'CODE' resource whose ID is 1) will always remain locked and
loaded and ready to fire.
Note: It is possible for a function to unload the segment of a function that called it. If that happens, the eventual return could be disastrous, since
the caller may have been swapped out.
Since the main segment never gets purged, it is OK to unload all other
segments from within that segment, even as often as each time through your
main loop. The unloaded code will be purged only during a memory shortage.
It will be loaded back in as soon as it is needed.